//
//  WJSVProgressHUDController.m
//  JerryIos
//
//  Created by jerrywang on 2018/2/8.
//  Copyright © 2018年 王军. All rights reserved.
//

#import "WJSVProgressHUDController.h"
#import "SVProgressHUD.h"

@interface WJSVProgressHUDController ()

@end

@implementation WJSVProgressHUDController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}


- (IBAction)show {
    [SVProgressHUD show];
    
    [self dismiss2after];
}

- (IBAction)showWithStatus {
    [SVProgressHUD showWithStatus:@"正在下载..."];
    
    [self dismissWithDelay];
}

static float progress = 0.0f;
- (IBAction)showWithProgress {
    progress = 0.0f;
    [SVProgressHUD showProgress:0 status:@"正在下载..."];
    [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.1f];
}

- (void)increaseProgress {
    progress += 0.05f;
    [SVProgressHUD showProgress:progress status:@"正在下载..."];
    
    if(progress < 1.0f){
        [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.1f];
    } else {
        [self performSelector:@selector(dismiss) withObject:nil afterDelay:0.4f];
    }
}

- (IBAction)showSuccessWithStatus {
    [SVProgressHUD showSuccessWithStatus:@"Great Success!"];
}

- (IBAction)showErrorWithStatus {
    [SVProgressHUD showErrorWithStatus:@"Failed with Error"];
}

- (IBAction)showInfoWithStatus {
    [SVProgressHUD showInfoWithStatus:@"Useful Information."];
}

- (IBAction)showImgWithStatus {
    [SVProgressHUD showImage:[UIImage imageNamed:@"icon_home"] status:@"image Information."];
}

- (IBAction)dismiss {
    [SVProgressHUD dismiss];
}



-(void)dismiss2after{
    // 模拟运行2秒后执行其他方法
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //此处执行两秒后的处理方法
        [SVProgressHUD dismiss];
    });
}

-(void)dismissWithDelay{
    [SVProgressHUD dismissWithDelay:2];
}

- (IBAction)changeStyle:(id)sender {
    UISegmentedControl *segmentedControl = (UISegmentedControl*)sender;
    if(segmentedControl.selectedSegmentIndex == 0){
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
    } else {
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    }
}

- (IBAction)changeAnimationType:(id)sender {
    UISegmentedControl *segmentedControl = (UISegmentedControl*)sender;
    if(segmentedControl.selectedSegmentIndex == 0){
        [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    } else {
        [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
    }
}

- (IBAction)changeMaskType:(id)sender {
    UISegmentedControl *segmentedControl = (UISegmentedControl*)sender;
    if(segmentedControl.selectedSegmentIndex == 0){
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    } else if(segmentedControl.selectedSegmentIndex == 1){
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    } else if(segmentedControl.selectedSegmentIndex == 2){
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    } else if(segmentedControl.selectedSegmentIndex == 3){
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeGradient];
    } else {
        [SVProgressHUD setBackgroundLayerColor:[[UIColor redColor] colorWithAlphaComponent:0.4]];
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeCustom];
    }
}


@end
